#include "wire.h"

Wire::Wire()
    : CircuitElement(2)
{
    this->updateEvents();
}

void Wire::onReceiveSignal(const Pin *pin, signed char signal)
{
    if (pins[0]== pin)
        pins[1]->send(signal);
    else
        pins[0]->send(signal);
}

void Wire::updateEvents()
{
    connect(this->pins[0],SIGNAL(OnReceive(const Pin*,signed char)),
            this,SLOT(onReceiveSignal(const Pin*,signed char)));
    connect(this->pins[1],SIGNAL(OnReceive(const Pin*,signed char)),
            this,SLOT(onReceiveSignal(const Pin*,signed char)));
}

Pin* Wire::createSpecialPIN()
{
    Pin *pin = CircuitElement::createSpecialPIN();
    connect(pin,SIGNAL(Receive(signed char)),this,SLOT(onReceiveSignal(const Pin&,signed char)));
    return pin;
}

void Wire::connectPins(Pin *left, Pin *right)
{
    pins.at(0)->connectPin(left);
    pins.at(1)->connectPin(right);
}
